/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<int> stree;
    vector<int> ttree;
public:
    bool isSubtree(TreeNode* s, TreeNode* t) {
        if(!s || !t){return false;}
        dfsTree(s,stree);
        dfsTree(t,ttree);
        for(int i=0;i<stree.size();i++){
            if(stree[i]==ttree[0]){
                int tmp=i;
                bool flag=true;
                for(int j=0;j<ttree.size();j++){
                    if(ttree[j]!=stree[tmp++]){flag=false;break;}
                }
                if(flag==true){return true;}
            }
        }
        return false;
    }
    void dfsTree(TreeNode* root,vector<int>&vec){
        if(root==nullptr){vec.push_back(-9999999);return;}
        vec.push_back(root->val);
        dfsTree(root->left,vec);
        dfsTree(root->right,vec);
    }
};